package com.example.vehicle.Performance;

import java.io.*;
import java.util.ArrayList;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @name: SimulateTest
 * @description: 仿真测试。
 * @author: Lulu Zhao
 **/
public class SimulateTest {

    /**
     * @name: readFile
     * @description: 按行读txt文件，返回字符串列表。
     * @params: []
     * @return: java.util.ArrayList<java.lang.String>
     * @author: Lulu Zhao
     */
    public static ArrayList<String> readFile() {
        File file = new File("src/10_right.txt");
        BufferedReader reader = null;
        String tempString;
        ArrayList<String> stringLists = new ArrayList<>();
        try {
            reader = new BufferedReader(new FileReader(file));
            while ((tempString = reader.readLine()) != null) {
                stringLists.add(tempString);
            }
            reader.close();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (reader != null) {
                try {
                    reader.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        return stringLists;
    }

    /**
     * @name: main
     * @description: 仿真测试主函数。
     * @params: [args]
     * @return: void
     * @author: Lulu Zhao
     */
    public static void main(String[] args) throws IOException, InterruptedException {
        ExecutorService executor = Executors.newSingleThreadExecutor();
        ArrayList<String> list = readFile();
        for (String s : list) {
            System.out.println(s);
            for (int j = 0; j < Integer.parseInt(s); j++) {
                executor.execute(new QueryVehicles());
            }
            executor.shutdown();
            Thread.sleep(999);
            executor = Executors.newSingleThreadExecutor();
        }
    }
}
